//
//  ViewControllerForMe.m
//  
//
//  Created by admin on 16/2/14.
//
//

#import "ViewControllerForMe.h"
#import "ViewControllerForCollect.h"

@interface ViewControllerForMe ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tabView;
@property(nonatomic,retain)NSMutableArray *arrDate;

@end

@implementation ViewControllerForMe

- (void)dealloc
{
    [super dealloc];
    
    [_tabView release];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    
    self.navigationItem.title = @"我";
    
    self.arrDate = @[
                     @{@"title" : @"我的收藏",
                       @"datial" : @"照片 视频 音乐",
                       @"image" : @"收藏"},
                     @{@"title" : @"清除缓存",
                       @"datial" : @"",
                       @"image" : @"缓存"},
                     @{@"title" : @"关于我们",
                       @"datial" : @"",
                       @"image" : @"我们"}
                     ].mutableCopy;
    
    [self createTabView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}




#pragma mark 创建TabView
- (void)createTabView
{
    self.tabView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    
    [self.view addSubview:self.tabView];
    
    self.tabView.dataSource = self;
    
    self.tabView.delegate = self;
    
    //去掉分割线
    self.tabView.separatorStyle = UITableViewCellSeparatorStyleNone;
}




#pragma mark UITableViewDataSource 协议方法
#pragma mark 相应分区的行的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
     return self.arrDate.count;
}



#pragma mark 给每行添加cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //创建重置池
    static NSString *str = @"pool";
    
    //从重置池中取出cell添加到table指定的section中的rom上
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    
    //如果重置池中没有可以重复利用的cell,则创建一个新的cell并放到此重置池中
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:str] autorelease];;
    }
    
    NSDictionary *dic = [self.arrDate objectAtIndex:indexPath.row];
    
    cell.textLabel.text = [dic objectForKey:@"title"];
    
    cell.detailTextLabel.text = [dic objectForKey:@"datial"];
    
    cell.imageView.image = [UIImage imageNamed:[dic objectForKey:@"image"]];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;

}



#pragma mark UITableViewDelegate 协议方法
#pragma mark 设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}



#pragma mark 选择相应的行所触发的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        ViewControllerForCollect *videoView = [[ViewControllerForCollect alloc] init];
        
        //1.设置self.tabBarController.tabBar.hidden=YES;
        self.tabBarController.tabBar.hidden = YES;
        
        //2.如果在push跳转时需要隐藏tabBar，设置self.hidesBottomBarWhenPushed=YES;
        self.hidesBottomBarWhenPushed=YES;
        
        [self.navigationController pushViewController:videoView animated:YES];
        
        //3.在push后设置self.hidesBottomBarWhenPushed=NO,这样back回来的时候，tabBar会恢复正常显示。
        self.hidesBottomBarWhenPushed=NO;
    }
}




@end
